package com.eling.elcms.travel.service.impl;

import com.eling.elcms.travel.model.RoomRegister;
import com.eling.elcms.travel.model.TravelContract;
import com.eling.elcms.travel.model.view.SettlementsResult;
import com.eling.elcms.travel.service.ISettlementsRule;
import com.eling.elcms.travel.util.DateHandlerUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 定额消费抵扣规则
 * @author Lina
 * 规则 ：满一个月的抵扣500元，满半个月的抵扣250元
 */
@Service
public class RegularExpenseServiceImpl implements ISettlementsRule {
	
	
	private static final Log log = LogFactory.getLog(RegularExpenseServiceImpl.class);
	

	@Override
	public SettlementsResult calculate(RoomRegister room, TravelContract contract, Date start, Date end) {
		log.debug("RegularExpenseServiceImpl");
		
		SettlementsResult result = new SettlementsResult();
		
		// 获取顾客居住天数:结算日期 - 入住日期
		Integer days = DateHandlerUtil.daysOfTwoDate(start, end);
				
		// 计算抵扣次数，以15天为一个抵扣单位，向上取整算出有多少个抵扣单位
		// 例如，36天，是一个月多6天，多出的6天不足半个月按半个月算，所以，应该是3个抵扣单位
		result.setPiece(Double.valueOf(days/15));
		
		// 计算抵扣金额:抵扣金额  = 250 * 抵扣单位
		result.setMoney(250 * result.getPiece());
		
		return result;
	}
	
}
